package com.sicheng.lc.周赛.分类.哈西表or计数or滑动窗口or双指针.抵消or期待某个元素;

import java.util.Arrays;

/**
 * @author zsc
 * @version 1.0
 * @date 2022/6/14 19:41
 */
public class 划分数组使最大差为K {
    //https://leetcode.cn/problems/partition-array-such-that-maximum-difference-is-k/
    public static void main(String[] args) {

    }

    public int partitionArray(int[] nums, int k) {
        Arrays.sort(nums);
        int count = 0;

        int l = 0;
        int r = 0;
        while (r < nums.length) {
            while (r < nums.length && nums[r] - nums[l] <= k) {
                r++;
            }

            count++;
            l = r;
            r++;
            if (r == nums.length && l < nums.length) {
                count++;
            }
        }


        return count;
    }
}
